/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.mad.bikepony.model.impl;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.json.JSON;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.impl.BaseModelImpl;
import com.liferay.portal.service.ServiceContext;

import com.liferay.portlet.expando.model.ExpandoBridge;
import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;

import com.mad.bikepony.model.Agent;
import com.mad.bikepony.model.AgentModel;
import com.mad.bikepony.model.AgentSoap;

import java.io.Serializable;

import java.sql.Types;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * The base model implementation for the Agent service. Represents a row in the &quot;bp_agent&quot; database table, with each column mapped to a property of this class.
 *
 * <p>
 * This implementation and its corresponding interface {@link com.mad.bikepony.model.AgentModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link AgentImpl}.
 * </p>
 *
 * @author nicola
 * @see AgentImpl
 * @see com.mad.bikepony.model.Agent
 * @see com.mad.bikepony.model.AgentModel
 * @generated
 */
@JSON(strict = true)
public class AgentModelImpl extends BaseModelImpl<Agent> implements AgentModel {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this class directly. All methods that expect a agent model instance should use the {@link com.mad.bikepony.model.Agent} interface instead.
	 */
	public static final String TABLE_NAME = "bp_agent";
	public static final Object[][] TABLE_COLUMNS = {
			{ "agentId", Types.BIGINT },
			{ "password_", Types.VARCHAR },
			{ "name", Types.VARCHAR },
			{ "surname", Types.VARCHAR },
			{ "mobilePhone", Types.VARCHAR },
			{ "status", Types.INTEGER },
			{ "lastPos_latitude", Types.DOUBLE },
			{ "lastPos_longitude", Types.DOUBLE },
			{ "lastUpdate", Types.BIGINT }
		};
	public static final String TABLE_SQL_CREATE = "create table bp_agent (agentId LONG not null primary key,password_ VARCHAR(75) null,name VARCHAR(75) null,surname VARCHAR(75) null,mobilePhone VARCHAR(75) null,status INTEGER,lastPos_latitude DOUBLE,lastPos_longitude DOUBLE,lastUpdate LONG)";
	public static final String TABLE_SQL_DROP = "drop table bp_agent";
	public static final String DATA_SOURCE = "liferayDataSource";
	public static final String SESSION_FACTORY = "liferaySessionFactory";
	public static final String TX_MANAGER = "liferayTransactionManager";
	public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.entity.cache.enabled.com.mad.bikepony.model.Agent"),
			true);
	public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.finder.cache.enabled.com.mad.bikepony.model.Agent"),
			true);
	public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.column.bitmask.enabled.com.mad.bikepony.model.Agent"),
			true);
	public static long AGENTID_COLUMN_BITMASK = 1L;
	public static long PASSWORD_COLUMN_BITMASK = 2L;
	public static long STATUS_COLUMN_BITMASK = 4L;

	/**
	 * Converts the soap model instance into a normal model instance.
	 *
	 * @param soapModel the soap model instance to convert
	 * @return the normal model instance
	 */
	public static Agent toModel(AgentSoap soapModel) {
		if (soapModel == null) {
			return null;
		}

		Agent model = new AgentImpl();

		model.setAgentId(soapModel.getAgentId());
		model.setPassword(soapModel.getPassword());
		model.setName(soapModel.getName());
		model.setSurname(soapModel.getSurname());
		model.setMobilePhone(soapModel.getMobilePhone());
		model.setStatus(soapModel.getStatus());
		model.setLastPos_latitude(soapModel.getLastPos_latitude());
		model.setLastPos_longitude(soapModel.getLastPos_longitude());
		model.setLastUpdate(soapModel.getLastUpdate());

		return model;
	}

	/**
	 * Converts the soap model instances into normal model instances.
	 *
	 * @param soapModels the soap model instances to convert
	 * @return the normal model instances
	 */
	public static List<Agent> toModels(AgentSoap[] soapModels) {
		if (soapModels == null) {
			return null;
		}

		List<Agent> models = new ArrayList<Agent>(soapModels.length);

		for (AgentSoap soapModel : soapModels) {
			models.add(toModel(soapModel));
		}

		return models;
	}

	public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.util.service.ServiceProps.get(
				"lock.expiration.time.com.mad.bikepony.model.Agent"));

	public AgentModelImpl() {
	}

	public long getPrimaryKey() {
		return _agentId;
	}

	public void setPrimaryKey(long primaryKey) {
		setAgentId(primaryKey);
	}

	public Serializable getPrimaryKeyObj() {
		return new Long(_agentId);
	}

	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey(((Long)primaryKeyObj).longValue());
	}

	public Class<?> getModelClass() {
		return Agent.class;
	}

	public String getModelClassName() {
		return Agent.class.getName();
	}

	@Override
	public Map<String, Object> getModelAttributes() {
		Map<String, Object> attributes = new HashMap<String, Object>();

		attributes.put("agentId", getAgentId());
		attributes.put("password", getPassword());
		attributes.put("name", getName());
		attributes.put("surname", getSurname());
		attributes.put("mobilePhone", getMobilePhone());
		attributes.put("status", getStatus());
		attributes.put("lastPos_latitude", getLastPos_latitude());
		attributes.put("lastPos_longitude", getLastPos_longitude());
		attributes.put("lastUpdate", getLastUpdate());

		return attributes;
	}

	@Override
	public void setModelAttributes(Map<String, Object> attributes) {
		Long agentId = (Long)attributes.get("agentId");

		if (agentId != null) {
			setAgentId(agentId);
		}

		String password = (String)attributes.get("password");

		if (password != null) {
			setPassword(password);
		}

		String name = (String)attributes.get("name");

		if (name != null) {
			setName(name);
		}

		String surname = (String)attributes.get("surname");

		if (surname != null) {
			setSurname(surname);
		}

		String mobilePhone = (String)attributes.get("mobilePhone");

		if (mobilePhone != null) {
			setMobilePhone(mobilePhone);
		}

		Integer status = (Integer)attributes.get("status");

		if (status != null) {
			setStatus(status);
		}

		Double lastPos_latitude = (Double)attributes.get("lastPos_latitude");

		if (lastPos_latitude != null) {
			setLastPos_latitude(lastPos_latitude);
		}

		Double lastPos_longitude = (Double)attributes.get("lastPos_longitude");

		if (lastPos_longitude != null) {
			setLastPos_longitude(lastPos_longitude);
		}

		Long lastUpdate = (Long)attributes.get("lastUpdate");

		if (lastUpdate != null) {
			setLastUpdate(lastUpdate);
		}
	}

	@JSON
	public long getAgentId() {
		return _agentId;
	}

	public void setAgentId(long agentId) {
		_columnBitmask |= AGENTID_COLUMN_BITMASK;

		if (!_setOriginalAgentId) {
			_setOriginalAgentId = true;

			_originalAgentId = _agentId;
		}

		_agentId = agentId;
	}

	public long getOriginalAgentId() {
		return _originalAgentId;
	}

	@JSON
	public String getPassword() {
		if (_password == null) {
			return StringPool.BLANK;
		}
		else {
			return _password;
		}
	}

	public void setPassword(String password) {
		_columnBitmask |= PASSWORD_COLUMN_BITMASK;

		if (_originalPassword == null) {
			_originalPassword = _password;
		}

		_password = password;
	}

	public String getOriginalPassword() {
		return GetterUtil.getString(_originalPassword);
	}

	@JSON
	public String getName() {
		if (_name == null) {
			return StringPool.BLANK;
		}
		else {
			return _name;
		}
	}

	public void setName(String name) {
		_name = name;
	}

	@JSON
	public String getSurname() {
		if (_surname == null) {
			return StringPool.BLANK;
		}
		else {
			return _surname;
		}
	}

	public void setSurname(String surname) {
		_surname = surname;
	}

	@JSON
	public String getMobilePhone() {
		if (_mobilePhone == null) {
			return StringPool.BLANK;
		}
		else {
			return _mobilePhone;
		}
	}

	public void setMobilePhone(String mobilePhone) {
		_mobilePhone = mobilePhone;
	}

	@JSON
	public int getStatus() {
		return _status;
	}

	public void setStatus(int status) {
		_columnBitmask |= STATUS_COLUMN_BITMASK;

		if (!_setOriginalStatus) {
			_setOriginalStatus = true;

			_originalStatus = _status;
		}

		_status = status;
	}

	public int getOriginalStatus() {
		return _originalStatus;
	}

	@JSON
	public double getLastPos_latitude() {
		return _lastPos_latitude;
	}

	public void setLastPos_latitude(double lastPos_latitude) {
		_lastPos_latitude = lastPos_latitude;
	}

	@JSON
	public double getLastPos_longitude() {
		return _lastPos_longitude;
	}

	public void setLastPos_longitude(double lastPos_longitude) {
		_lastPos_longitude = lastPos_longitude;
	}

	@JSON
	public long getLastUpdate() {
		return _lastUpdate;
	}

	public void setLastUpdate(long lastUpdate) {
		_lastUpdate = lastUpdate;
	}

	public long getColumnBitmask() {
		return _columnBitmask;
	}

	@Override
	public ExpandoBridge getExpandoBridge() {
		return ExpandoBridgeFactoryUtil.getExpandoBridge(0,
			Agent.class.getName(), getPrimaryKey());
	}

	@Override
	public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
		ExpandoBridge expandoBridge = getExpandoBridge();

		expandoBridge.setAttributes(serviceContext);
	}

	@Override
	public Agent toEscapedModel() {
		if (_escapedModelProxy == null) {
			_escapedModelProxy = (Agent)ProxyUtil.newProxyInstance(_classLoader,
					_escapedModelProxyInterfaces,
					new AutoEscapeBeanHandler(this));
		}

		return _escapedModelProxy;
	}

	@Override
	public Object clone() {
		AgentImpl agentImpl = new AgentImpl();

		agentImpl.setAgentId(getAgentId());
		agentImpl.setPassword(getPassword());
		agentImpl.setName(getName());
		agentImpl.setSurname(getSurname());
		agentImpl.setMobilePhone(getMobilePhone());
		agentImpl.setStatus(getStatus());
		agentImpl.setLastPos_latitude(getLastPos_latitude());
		agentImpl.setLastPos_longitude(getLastPos_longitude());
		agentImpl.setLastUpdate(getLastUpdate());

		agentImpl.resetOriginalValues();

		return agentImpl;
	}

	public int compareTo(Agent agent) {
		long primaryKey = agent.getPrimaryKey();

		if (getPrimaryKey() < primaryKey) {
			return -1;
		}
		else if (getPrimaryKey() > primaryKey) {
			return 1;
		}
		else {
			return 0;
		}
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}

		Agent agent = null;

		try {
			agent = (Agent)obj;
		}
		catch (ClassCastException cce) {
			return false;
		}

		long primaryKey = agent.getPrimaryKey();

		if (getPrimaryKey() == primaryKey) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (int)getPrimaryKey();
	}

	@Override
	public void resetOriginalValues() {
		AgentModelImpl agentModelImpl = this;

		agentModelImpl._originalAgentId = agentModelImpl._agentId;

		agentModelImpl._setOriginalAgentId = false;

		agentModelImpl._originalPassword = agentModelImpl._password;

		agentModelImpl._originalStatus = agentModelImpl._status;

		agentModelImpl._setOriginalStatus = false;

		agentModelImpl._columnBitmask = 0;
	}

	@Override
	public CacheModel<Agent> toCacheModel() {
		AgentCacheModel agentCacheModel = new AgentCacheModel();

		agentCacheModel.agentId = getAgentId();

		agentCacheModel.password = getPassword();

		String password = agentCacheModel.password;

		if ((password != null) && (password.length() == 0)) {
			agentCacheModel.password = null;
		}

		agentCacheModel.name = getName();

		String name = agentCacheModel.name;

		if ((name != null) && (name.length() == 0)) {
			agentCacheModel.name = null;
		}

		agentCacheModel.surname = getSurname();

		String surname = agentCacheModel.surname;

		if ((surname != null) && (surname.length() == 0)) {
			agentCacheModel.surname = null;
		}

		agentCacheModel.mobilePhone = getMobilePhone();

		String mobilePhone = agentCacheModel.mobilePhone;

		if ((mobilePhone != null) && (mobilePhone.length() == 0)) {
			agentCacheModel.mobilePhone = null;
		}

		agentCacheModel.status = getStatus();

		agentCacheModel.lastPos_latitude = getLastPos_latitude();

		agentCacheModel.lastPos_longitude = getLastPos_longitude();

		agentCacheModel.lastUpdate = getLastUpdate();

		return agentCacheModel;
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(19);

		sb.append("{agentId=");
		sb.append(getAgentId());
		sb.append(", password=");
		sb.append(getPassword());
		sb.append(", name=");
		sb.append(getName());
		sb.append(", surname=");
		sb.append(getSurname());
		sb.append(", mobilePhone=");
		sb.append(getMobilePhone());
		sb.append(", status=");
		sb.append(getStatus());
		sb.append(", lastPos_latitude=");
		sb.append(getLastPos_latitude());
		sb.append(", lastPos_longitude=");
		sb.append(getLastPos_longitude());
		sb.append(", lastUpdate=");
		sb.append(getLastUpdate());
		sb.append("}");

		return sb.toString();
	}

	public String toXmlString() {
		StringBundler sb = new StringBundler(31);

		sb.append("<model><model-name>");
		sb.append("com.mad.bikepony.model.Agent");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>agentId</column-name><column-value><![CDATA[");
		sb.append(getAgentId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>password</column-name><column-value><![CDATA[");
		sb.append(getPassword());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>name</column-name><column-value><![CDATA[");
		sb.append(getName());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>surname</column-name><column-value><![CDATA[");
		sb.append(getSurname());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>mobilePhone</column-name><column-value><![CDATA[");
		sb.append(getMobilePhone());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>status</column-name><column-value><![CDATA[");
		sb.append(getStatus());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>lastPos_latitude</column-name><column-value><![CDATA[");
		sb.append(getLastPos_latitude());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>lastPos_longitude</column-name><column-value><![CDATA[");
		sb.append(getLastPos_longitude());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>lastUpdate</column-name><column-value><![CDATA[");
		sb.append(getLastUpdate());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private static ClassLoader _classLoader = Agent.class.getClassLoader();
	private static Class<?>[] _escapedModelProxyInterfaces = new Class[] {
			Agent.class
		};
	private long _agentId;
	private long _originalAgentId;
	private boolean _setOriginalAgentId;
	private String _password;
	private String _originalPassword;
	private String _name;
	private String _surname;
	private String _mobilePhone;
	private int _status;
	private int _originalStatus;
	private boolean _setOriginalStatus;
	private double _lastPos_latitude;
	private double _lastPos_longitude;
	private long _lastUpdate;
	private long _columnBitmask;
	private Agent _escapedModelProxy;
}